const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class AlipayReturnHandler extends BaseHandler {

    get pattern() {
        return '/alipay/return_url';
    }

    doAll(request, response) {
        var params = request.query || request.body;

        this.Controller.finishPurchase(params, 'return_data', (result) => {
            if(result.success) {
                response.redirect('/console');
            } else {
                response.end('ERROR: ' + result.error);
            }
        });

    }

    setup() {
        this.registerVerb(HTTP_VERBS.ALL, this.doAll);
    }
}

module.exports = AlipayReturnHandler;